package com.fc.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fc.checkGroup.Delete;
import com.fc.checkGroup.Insert;
import com.fc.checkGroup.Select;
import com.fc.checkGroup.Update;
import com.fc.entity.ShoppingCar;
import com.fc.entity.input.DeleteBatchInput;
import com.fc.entity.input.ShoppingCarInput;
import com.fc.entity.input.ShoppingCarQueryInput;
import com.fc.entity.output.ShoppingCarOutput;
import com.fc.entity.query.PageQuery;
import com.fc.entity.query.PageResult;
import com.fc.service.ShoppingCarService;
import com.fc.utils.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 购物车 前端控制器
 * </p>
 *
 * @author
 * @since 2024-11-07
 */
@RestController
@RequestMapping("/shoppingCar")
@Validated
@Slf4j
@Tag(name = "购物车接口")
public class ShoppingCarController {

    @Autowired
    private ShoppingCarService shoppingCarService;


    /**
     * 新增
     */
    @Operation(summary = "新增商品")
    @PostMapping("/add")
    public ResultVO<String> add(@Validated(Insert.class) @RequestBody ShoppingCarInput input) {
        log.info("购物车新增");
        return shoppingCarService.add(input) ? ResultVO.success("新增成功") : ResultVO.error("新增失败");
    }

    /**
     * 分页模糊查询
     */
    @Operation(summary = "分页查询")
    @GetMapping("page")
    public ResultVO<PageResult<ShoppingCarOutput>> getPage(PageQuery query, ShoppingCarQueryInput input) {
        log.info("购物车分页查询");
        IPage<ShoppingCarOutput> page = shoppingCarService.getPage(query, input);
        return ResultVO.success(PageResult.fromIPage(page));
    }

    /**
     * 修改
     */
/*    @Operation(summary = "修改")
    @PostMapping("/renew")
    public ResultVO<String> renew(@Validated(Update.class) @RequestBody ShoppingCarInput input) {
        log.info("购物车修改");
        return shoppingCarService.renew(input) ? ResultVO.success("修改成功") : ResultVO.error("修改失败");
    }*/

    /**
     * 删除
     */
    @Operation(summary = "删除商品")
    @PostMapping("del")
    public ResultVO<String> del(@Validated(Delete.class) @RequestBody DeleteBatchInput input) {
        log.info("购物车删除");
        return shoppingCarService.del(input) ? ResultVO.success("删除成功") : ResultVO.error("删除失败");
    }

    /**
     * 购物车商品数据加减
     */
    @Operation(summary = "商品数量加减")
    @PostMapping("addNum")
    public ResultVO<String> addNum(@Validated(Select.class) @RequestBody ShoppingCarInput input) {
        log.info("购物车商品数量加减");
        return shoppingCarService.addNum(input) ? ResultVO.success("修改数量成功") : ResultVO.error("修改数量失败");
    }
}
